import React from 'react';
import { Form, Input, Modal } from 'antd';
import moment from 'moment';

const formItemLayout = {
  labelCol: {
    span: 6,
  },
  wrapperCol: {
    span: 14,
  },
};

const modal = ({
  item = {},
  onOk,
  form: {
    getFieldDecorator,
    validateFields,
    getFieldsValue,
  },
  modalType,
  ...modalProps
}) => {
  const handleOk = () => {
    validateFields((errors) => {
      if (errors) {
        return;
      }
      onOk(getFieldsValue());
    });
  };

  const modalOpts = {
    ...modalProps,
    onOk: handleOk,
    title: modalType ? '修改vRegionSubnet' : '新建vRegionSubnet',
    okText: modalType ? '修改' : '创建',
  };

  const formItems = [];
  if (modalType) {
    formItems.push(
      <Form.Item label="UUID" key="UUID" {...formItemLayout}>
        {getFieldDecorator('id', {
          initialValue: item.id,
        })(<Input disabled />)}
      </Form.Item>);
  }
  formItems.push(
    <Form.Item label="name" key="name" hasFeedback {...formItemLayout}>
      {getFieldDecorator('name', {
        initialValue: item.name,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="description" key="description" hasFeedback {...formItemLayout}>
      {getFieldDecorator('description', {
        initialValue: item.description,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input type="textarea" />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="networkId" key="networkId" hasFeedback {...formItemLayout}>
      {getFieldDecorator('networkId', {
        initialValue: item.networkId,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="portSecurityEnabledprojectId" key="portSecurityEnabledprojectId" hasFeedback {...formItemLayout}>
      {getFieldDecorator('portSecurityEnabledprojectId', {
        initialValue: item.portSecurityEnabledprojectId,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="dnsServer" key="dnsServer" hasFeedback {...formItemLayout}>
      {getFieldDecorator('dnsServer', {
        initialValue: item.dnsServer,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="enableDHCP" key="enableDHCP" hasFeedback {...formItemLayout}>
      {getFieldDecorator('enableDHCP', {
        initialValue: item.enableDHCP,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="allocationPool" key="allocationPool" hasFeedback {...formItemLayout}>
      {getFieldDecorator('allocationPool', {
        initialValue: item.allocationPool,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="hostRoutesStr" key="hostRoutesStr" hasFeedback {...formItemLayout}>
      {getFieldDecorator('hostRoutesStr', {
        initialValue: item.hostRoutesStr,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);

  formItems.push(
    <Form.Item label="ipVersion" key="ipVersion" hasFeedback {...formItemLayout}>
      {getFieldDecorator('ipVersion', {
        initialValue: item.ipVersion,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="gatewayIP" key="gatewayIP" hasFeedback {...formItemLayout}>
      {getFieldDecorator('gatewayIP', {
        initialValue: item.gatewayIP,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="ipv6AddressMode" key="ipv6AddressMode" hasFeedback {...formItemLayout}>
      {getFieldDecorator('ipv6AddressMode', {
        initialValue: item.ipv6AddressMode,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="ipv6RaMode" key="ipv6RaMode" hasFeedback {...formItemLayout}>
      {getFieldDecorator('ipv6RaMode', {
        initialValue: item.ipv6RaMode,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="segmentId" key="segmentId" hasFeedback {...formItemLayout}>
      {getFieldDecorator('segmentId', {
        initialValue: item.segmentId,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="subnetpoolId" key="subnetpoolId" hasFeedback {...formItemLayout}>
      {getFieldDecorator('subnetpoolId', {
        initialValue: item.subnetpoolId,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="revision_number" key="revision_number" hasFeedback {...formItemLayout}>
      {getFieldDecorator('revision_number', {
        initialValue: item.revision_number,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="serviceTypes" key="serviceTypes" hasFeedback {...formItemLayout}>
      {getFieldDecorator('serviceTypes', {
        initialValue: item.serviceTypes,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="subnetType" key="subnetType" hasFeedback {...formItemLayout}>
      {getFieldDecorator('subnetType', {
        initialValue: item.subnetType,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="regionType" key="regionType" hasFeedback {...formItemLayout}>
      {getFieldDecorator('regionType', {
        initialValue: item.regionType,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="regionId" key="regionId" hasFeedback {...formItemLayout}>
      {getFieldDecorator('regionId', {
        initialValue: item.regionId,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="activeControllerList" key="activeControllerList" hasFeedback {...formItemLayout}>
      {getFieldDecorator('activeControllerList', {
        initialValue: item.activeControllerList,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);
  formItems.push(
    <Form.Item label="cidr" key="cidr" hasFeedback {...formItemLayout}>
      {getFieldDecorator('cidr', {
        initialValue: item.cidr,
        rules: [
          {
            required: true,
          },
        ],
      })(<Input />)}
    </Form.Item>);

  return (
    <Modal

      {...modalOpts}
    >
      <Form layout="horizontal">
        {formItems}
      </Form>
    </Modal>
  );
};

export default Form.create()(modal);
